package com.niyue.sandbox.uclock.core;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;
import org.joda.time.DateTime;

public class SecondTickerEventFactory implements EventFactory {
	private static Logger logger = Logger.getLogger(SecondTickerEventFactory.class);
	private static List < Event > eventList;
	
	public void addEvent(Event event){
		eventList.add(event);
	}
	public SecondTickerEventFactory() {
		eventList=new ArrayList <Event >();
		Thread secondThread = new SecondThread(this);
		secondThread.start();
	}
	/**
	 * 
	 */
	public final List < Event > getEvents(final DateTime datetime) {
		if (logger.isDebugEnabled()) {
			logger.debug(datetime+" ticker event");
		}
		List< Event > tickerList = new ArrayList< Event >();
		tickerList.addAll(eventList);
		eventList.removeAll(eventList);
		return tickerList;
	}
}
